package inline;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.media.ExifInterface;
import android.support.annotation.NonNull;

import java.io.IOException;

public class BitmapDemo {
    public static int a(BitmapFactory.Options arg5, int arg6, int arg7) {
        int v2 = arg5.outHeight;
        int v3 = arg5.outWidth;
        int v0 = 1;
        if (v2 > arg7 || v3 > arg6) {
            v0 = Math.round((((float) v2)) / (((float) arg7)));
            int v1 = Math.round((((float) v3)) / (((float) arg6)));
            if (v0 >= v1) {
                v0 = v1;
            }
        }

        float v1_1 = ((float) (v3 * v2));
        float v2_1 = ((float) (arg6 * arg7 << 1));
        while (v1_1 / (((float) (v0 * v0))) > v2_1) {
            ++v0;
        }

        return v0;
    }

    public static Bitmap e(String arg11) {
        Matrix v5_1;
        Bitmap v3_1;
        Bitmap v0 = null;
        int v2 = 114;
        float v7 = 114f;
        BitmapFactory.Options v4 = new BitmapFactory.Options();
        v4.inJustDecodeBounds = true;
        int v3 = v4.outHeight;
        int v1 = v4.outWidth;
        if (v3 > 0 && v1 > 0) {
            float v5 = (((float) v1)) / (((float) v3));
            if ((((float) v3)) <= v7 && (((float) v1)) <= v7) {
                v2 = v3;
            } else if (v5 < 1f) {
                int v10 = v2;
                v2 = ((int) (v7 / (((float) v1)) * (((float) v3))));
                v1 = v10;
            } else if (v5 > 1f) {
                v1 = ((int) ((((float) v1)) * (v7 / (((float) v3)))));
            } else {
                v1 = v2;
            }

            if (v2 <= 0) {
                return v0;
            }

            if (v1 <= 0) {
                return v0;
            }

            v4.inSampleSize = BitmapDemo.a(v4, v1, v2);
            v4.inJustDecodeBounds = false;
            v4.inPurgeable = true;
            v4.inInputShareable = true;
            v4.inTempStorage = new byte[16384];
            try {
                v3_1 = BitmapFactory.decodeFile(arg11, v4);
            } catch (OutOfMemoryError v1_1) {
                return v0;
            }

            v5 = (((float) v1)) / (((float) v4.outWidth));
            float v4_1 = (((float) v2)) / (((float) v4.outHeight));
            float v6 = (((float) v1)) / 2f;
            v7 = (((float) v2)) / 2f;
            Matrix v8 = new Matrix();
            v8.setScale(v5, v4_1, v6, v7);
            try {
                v0 = Bitmap.createBitmap(v1, v2, Bitmap.Config.ARGB_8888);
            } catch (OutOfMemoryError v1_1) {
                return v0;
            }

            Canvas v1_2 = new Canvas(v0);
            v1_2.setMatrix(v8);
            v1_2.drawBitmap(v3_1, v6 - (((float) (v3_1.getWidth() / 2))), v7 - (((float) (v3_1.getHeight() / 2))), new Paint(2));
            v3_1.recycle();
            try {
                v1 = new ExifInterface(arg11).getAttributeInt("Orientation", 0);
                v5_1 = new Matrix();
                if (v1 == 6) {
                    v5_1.postRotate(90f);
                } else if (v1 == 3) {
                    v5_1.postRotate(180f);
                } else {
                    if (v1 == 8) {
                        float v1_4 = 270f;
                        v5_1.postRotate(v1_4);
                    }
                }
                v0 = Bitmap.createBitmap(v0, 0, 0, v0.getWidth(), v0.getHeight(), v5_1, true);
            } catch (IOException v1_3) {
                v1_3.printStackTrace();
            }
        }

        return v0;
    }

    public static Bitmap b(String arg5) {
        Bitmap v0;
        Bitmap v1 = null;
        Bitmap v2 = BitmapDemo.e(arg5);
        if (v2 == null) {
            v0 = v1;
            return v0;
        }

        int v0_1 = v2.getHeight() > v2.getWidth() ? v2.getWidth() : v2.getHeight();
        try {
            v0 = Bitmap.createBitmap(v2, (v2.getWidth() - v0_1) / 2, (v2.getHeight() - v0_1) / 2, v0_1, v0_1);
        } catch (OutOfMemoryError v0_2) {
            v0 = v1;
        }

        return v0;
    }

    @NonNull
    public static Bitmap a(Bitmap src) {
        int px = ResourcesDemo.dp2px(4f);
        Bitmap dst = Bitmap.createBitmap(src.getWidth() + px, src.getHeight() + px, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(dst);
        canvas.drawARGB(0, 0, 0, 0);
        canvas.drawBitmap(src, ((float) (px / 2)), ((float) (px / 2)), new Paint(2));
        return dst;
    }
}
